<?php

namespace App;

use App\Model\Dpt;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'realname', 'dpt_id'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $appends = ['dpt'];

    /**
     * 添加返回的部门属性
     */
    public function getDptAttribute(){
        $id = $this->attributes['dpt_id'];
        $dpt = Dpt::find($id);
        return $dpt ? $dpt->name : '无';
    }
}
